<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:54:"E:\thinkphp\officiaWeb\public/tpl/admin\nav\index.html";i:1564247136;s:56:"E:\thinkphp\officiaWeb\public\tpl\admin\public\base.html";i:1563270889;}*/ ?>
<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>后台管理-菜单列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="\static\x-admin/css/font.css">
        <link rel="stylesheet" href="\static\x-admin/css/xadmin.css">
        <script type="text/javascript" src="\static/resources/js/jquery/jquery-2.0.0.min.js"></script>
        <script type="text/javascript" src="\static\x-admin/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="\static\x-admin/js/xadmin.js"></script>

        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <script>
        // 是否开启刷新记忆tab功能
        // var is_remember = false;
    </script>
    <style type="text/css"></style>
    <body>
    	
  <div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="<?php echo url('admin/index/index'); ?>">首页</a>
        <a>
            <cite>菜单列表</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn"  type="button" lay-submit="" lay-filter="sreach" onclick="xadmin.open('添加菜单','<?php echo url('admin/nav/add'); ?>',600,400)"><i class="layui-icon"></i>添加菜单</button>
                        </div>
                    </form>
                    <hr>
                </div>
                
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                      <thead>
                        <tr>
                          <th width="70">序号</th>
                          <th width="30">图标</th>
                          <th>菜单名称</th>
                          <th>连接名</th>
                          <th width="50">排序</th>
                          <th width="250">操作</th>
                      </thead>
                      <tbody class="x-cate">
                        <?php if(is_array($data) || $data instanceof \think\Collection || $data instanceof \think\Paginator): $k = 0; $__LIST__ = $data;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($k % 2 );++$k;?>
                        <tr cate-id='<?php echo $v["id"]; ?>' fid='<?php echo $v["pid"]; ?>' ><!-- cate-id是ID  fid是父级ID   -->
                            <td>
                                <?php echo $k; ?>
                            </td>
                            <td>
                                <i class="iconfont" ><?php echo $v['ico']; ?></i>
                            </td>
                            <td>
                              <!-- 父级自己分类 -->
                                <?php $__FOR_START_417872118__=0;$__FOR_END_417872118__=$v['level'];for($i=$__FOR_START_417872118__;$i < $__FOR_END_417872118__;$i+=1){ ?>
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                <?php } if($v['child']): ?>
                                    <i class="layui-icon x-show iconfont" status='true'>&#xe623;</i>
                                <?php else: if($v['level'] != 0): ?>
                                    |--
                                  <?php endif; endif; ?>
                                <?php echo $v['name']; ?>
                            </td>
                            <td>
                                <?php echo $v['mac']; ?>
                            </td>
                            <td>
                                <input type="text" class="layui-input x-sort" name="sort[]" id="<?php echo $v['id']; ?>" value="<?php echo $v['sort']; ?>">
                            </td>
                            <td class="td-manage">
                                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('修改<?php echo $v['name']; ?>菜单','<?php echo url('admin/nav/edit',array('id'=>$v['id'])); ?>',600,400)" >
                                  <i class="layui-icon">&#xe642;</i>编辑
                                </button>
                                <?php if($v['level'] < '2'): ?>
                                  <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('添加子栏目','<?php echo url('admin/nav/add',array('pid'=>$v['id'])); ?>',600,400)" >
                                    <i class="layui-icon">&#xe642;</i>添加子栏目
                                  </button>
                                <?php endif; ?>
                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'<?php echo $v['id']; ?>')" href="javascript:;" >
                                  <i class="layui-icon">&#xe640;</i>删除
                                </button>
                            </td>
                        </tr>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                      </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <form class="layui-form layui-col-space5">
                          <div class="layui-input-inline layui-show-xs-block">
                              <button class="layui-btn"  type="button" lay-submit="" onclick="saveSort()" lay-filter="sreach" ><i class="iconfont">&#xea97;</i>保存</button>
                          </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

        
  <script>
    layui.use(['form'], function(){
      form = layui.form;
      
    });

     /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
          // console.log(id);
            //发异步删除数据
            let data = {
              'id':id
            };
            $.post("<?php echo url('admin/nav/del'); ?>",data,function(e){
              if(e.code == 200){
                  $(obj).parents("tr").remove();
                  layer.msg(e.msg,{icon:1,time:1000});
                  // 可以对父窗口进行刷新 
                  xadmin.father_reload();
              }else{
                  layer.msg(e.msg,{icon:2,time:1000});
              }
              return true;
            });
        });
    }

    // 分类展开收起的分类的逻辑
    // 
    $(function(){
      $("tbody.x-cate tr[fid!='0']").hide();
      // 栏目多级显示效果
      $('.x-show').click(function () {
          if($(this).attr('status')=='true'){
              $(this).html('&#xe625;'); 
              $(this).attr('status','false');
              cateId = $(this).parents('tr').attr('cate-id');
              $("tbody tr[fid="+cateId+"]").show();
         }else{
              cateIds = [];
              $(this).html('&#xe623;');
              $(this).attr('status','true');
              cateId = $(this).parents('tr').attr('cate-id');
              getCateId(cateId);
              for (var i in cateIds) {
                  $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
              }
         }
      })
    })

    var cateIds = [];
    function getCateId(cateId) {
        $("tbody tr[fid="+cateId+"]").each(function(index, el) {
            id = $(el).attr('cate-id');
            cateIds.push(id);
            getCateId(id);
        });
    }


    //排序编号保存
    function saveSort(){
      let sortarr = $('input[name="sort[]"]');
      let data = {};
      let temp;
      for (var i =  0; sortarr.length > i; i++) {
          temp = $(sortarr[i]);
          data[i] = {};
          data[i]['id'] = temp[0].id;
          data[i]['sort'] = temp.val();
      }
      data  = {
        'data':JSON.stringify(data)
      };
      $.post("<?php echo url('admin/nav/saveSort'); ?>",data,function(e){
        if(e.code == 200){
            layer.msg(e.msg,{icon:1,time:3000});
            location.reload();
            // 可以对父窗口进行刷新 
            xadmin.father_reload();
            return true; 
        }else{
            layer.msg(e.msg,{icon:2,time:3000});
        }
        return true;
      });
    }

  </script>

    </body>
</html>
